﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import flash.events.*;
    import flash.display.*;
    import org.aswing.geom.*;
    import org.aswing.plaf.*;
    import org.aswing.event.*;
    import org.aswing.resizer.*;
    import org.aswing.plaf.basic.*;

    public class JFrame extends JWindow {

        public static const NORMAL:int = 0;
        public static const ICONIFIED:int = 2;
        public static const MAXIMIZED_HORIZ:int = 4;
        public static const MAXIMIZED_VERT:int = 8;
        public static const MAXIMIZED:int = 12;
        public static const DO_NOTHING_ON_CLOSE:int = 0;
        public static const HIDE_ON_CLOSE:int = 1;
        public static const DISPOSE_ON_CLOSE:int = 2;
        public static const PROPERTY_TITLE_BAR:String = "titleBar";

        protected var titleBar:FrameTitleBar;
        protected var title:String;
        protected var icon:Icon;
        protected var state:int;
        protected var defaultCloseOperation:int;
        protected var maximizedBounds:IntRectangle;
        protected var lastNormalStateBounds:IntRectangle;
        protected var dragable:Boolean;
        protected var resizable:Boolean;
        protected var closable:Boolean;
        protected var dragDirectly:Boolean;
        protected var dragDirectlySet:Boolean;
        protected var resizer:Resizer;
        protected var resizerController:ResizerController;

        public function JFrame(_arg1=null, _arg2:String="", _arg3:Boolean=false){
            super(_arg1, _arg3);
            this.title = _arg2;
            this.state = NORMAL;
            this.defaultCloseOperation = DISPOSE_ON_CLOSE;
            this.dragable = true;
            this.resizable = true;
            this.closable = true;
            this.icon = DefaultEmptyDecoraterResource.INSTANCE;
            this.lastNormalStateBounds = new IntRectangle(0, 0, 200, 100);
            setName("JFrame");
            addEventListener(Event.ADDED_TO_STAGE, this.__frameAddedToStage);
            addEventListener(Event.REMOVED_FROM_STAGE, this.__frameRemovedFromStage);
            addEventListener(MovedEvent.MOVED, this.__frameMoved);
            this.updateUI();
            this.setTitleBar(new JFrameTitleBar());
        }
        override public function updateUI():void{
            this.setUI(UIManager.getUI(this));
        }
        override public function getDefaultBasicUIClass():Class{
            return (BasicFrameUI);
        }
        override public function setUI(_arg1:ComponentUI):void{
            if ((_arg1 is FrameUI)){
                super.setUI(_arg1);
            } else {
                throw (new ArgumentError("JFrame just accept FrameUI instance!!!"));
            };
        }
        public function getTitleBar():FrameTitleBar{
            return (this.titleBar);
        }
        public function setTitleBar(_arg1:FrameTitleBar):void{
            var _local2:FrameTitleBar;
            if (this.titleBar != _arg1){
                _local2 = this.titleBar;
                if (this.titleBar){
                    this.titleBar.setFrame(null);
                    remove(this.titleBar.getSelf());
                };
                this.titleBar = _arg1;
                if (this.titleBar){
                    this.titleBar.setText(this.getTitle());
                    this.titleBar.setIcon(this.getIcon());
                    insert(0, this.titleBar.getSelf(), WindowLayout.TITLE);
                    this.titleBar.setFrame(this);
                };
                dispatchEvent(new PropertyChangeEvent(PROPERTY_TITLE_BAR, _local2, _arg1));
            };
        }
        public function getFrameUI():FrameUI{
            return ((getUI() as FrameUI));
        }
        override public function getUIClassID():String{
            return ("FrameUI");
        }
        public function setTitle(_arg1:String):void{
            if (this.title != _arg1){
                this.title = _arg1;
                if (this.getTitleBar()){
                    this.getTitleBar().setText(_arg1);
                };
                repaint();
                revalidate();
            };
        }
        public function getTitle():String{
            return (this.title);
        }
        public function setIcon(_arg1:Icon):void{
            if (this.icon != _arg1){
                this.icon = _arg1;
                if (this.getTitleBar()){
                    this.getTitleBar().setIcon(_arg1);
                };
                repaint();
                revalidate();
            };
        }
        public function getIcon():Icon{
            return (this.icon);
        }
        public function setResizable(_arg1:Boolean):void{
            if (this.resizable != _arg1){
                this.resizable = _arg1;
                this.getResizer().setEnabled(_arg1);
                repaint();
                dispatchEvent(new FrameEvent(FrameEvent.FRAME_ABILITY_CHANGED, true));
            };
        }
        public function isResizable():Boolean{
            return (this.resizable);
        }
        public function setDragable(_arg1:Boolean):void{
            if (this.dragable != _arg1){
                this.dragable = _arg1;
                repaint();
                revalidate();
                dispatchEvent(new FrameEvent(FrameEvent.FRAME_ABILITY_CHANGED, true));
            };
        }
        public function isDragable():Boolean{
            return (this.dragable);
        }
        public function setClosable(_arg1:Boolean):void{
            if (this.closable != _arg1){
                this.closable = _arg1;
                repaint();
                dispatchEvent(new FrameEvent(FrameEvent.FRAME_ABILITY_CHANGED, true));
            };
        }
        public function isClosable():Boolean{
            return (this.closable);
        }
        override public function pack():void{
            if (this.getState() == NORMAL){
                super.pack();
            };
        }
        public function getMaximizedBounds():IntRectangle{
            var _local1:IntRectangle;
            if (this.maximizedBounds == null){
                _local1 = AsWingUtils.getVisibleMaximizedBounds(this.parent);
                return (getInsets().getOutsideBounds(_local1));
            };
            return (this.maximizedBounds.clone());
        }
        public function setMaximizedBounds(_arg1:IntRectangle):void{
            if (_arg1 != null){
                this.maximizedBounds = _arg1.clone();
                revalidate();
            } else {
                this.maximizedBounds = null;
            };
        }
        public function setDefaultCloseOperation(_arg1:int):void{
            if (((((!((_arg1 == DO_NOTHING_ON_CLOSE))) && (!((_arg1 == HIDE_ON_CLOSE))))) && (!((_arg1 == DISPOSE_ON_CLOSE))))){
                _arg1 = DISPOSE_ON_CLOSE;
            };
            this.defaultCloseOperation = _arg1;
        }
        public function getDefaultCloseOperation():int{
            return (this.defaultCloseOperation);
        }
        public function setState(_arg1:int, _arg2:Boolean=true):void{
            if (this.state != _arg1){
                if (this.state == NORMAL){
                    this.lastNormalStateBounds.setRect(getComBounds());
                };
                this.state = _arg1;
                this.fireStateChanged();
                if (this.state == ICONIFIED){
                    this.precessIconified(_arg2);
                } else {
                    if (((((this.state & MAXIMIZED_HORIZ) == MAXIMIZED_HORIZ)) || (((this.state & MAXIMIZED_VERT) == MAXIMIZED_VERT)))){
                        this.precessMaximized(_arg2);
                    } else {
                        this.precessRestored(_arg2);
                    };
                };
                this.doStateChange();
            };
        }
        protected function isMaximized():Boolean{
            return (((((this.state & MAXIMIZED_HORIZ) == MAXIMIZED_HORIZ)) || (((this.state & MAXIMIZED_VERT) == MAXIMIZED_VERT))));
        }
        protected function doStateChange():void{
            var _local1:IntDimension;
            var _local2:IntRectangle;
            if (this.state == ICONIFIED){
                _local1 = new IntDimension(60, 20);
                if (this.titleBar){
                    _local1 = this.titleBar.getSelf().getMinimumSize();
                };
                setSize(getInsets().getOutsideSize(_local1));
                _local2 = this.getMaximizedBounds();
                if (x < _local2.x){
                    x = _local2.x;
                };
            } else {
                if (this.state == NORMAL){
                    setBounds(this.lastNormalStateBounds);
                } else {
                    this.setSizeToFixMaxmimized();
                };
            };
            if (this.getResizer() != null){
                this.getResizer().setEnabled(((this.isResizable()) && ((this.state == JFrame.NORMAL))));
            };
            revalidateIfNecessary();
        }
        private function __frameMoved(_arg1:MovedEvent):void{
            if (this.state == ICONIFIED){
                this.lastNormalStateBounds.setLocation(_arg1.getNewLocation());
            };
        }
        private function __frameAddedToStage(_arg1:Event):void{
            stage.addEventListener(Event.RESIZE, this.__frameStageResized, false, 0, true);
        }
        private function __frameRemovedFromStage(_arg1:Event):void{
            stage.removeEventListener(Event.RESIZE, this.__frameStageResized);
        }
        private function __frameStageResized(_arg1:Event=null):void{
            if ((((stage == null)) || (!((stage.scaleMode == StageScaleMode.NO_SCALE))))){
                return;
            };
            if (this.isMaximized()){
                this.setSizeToFixMaxmimized();
                revalidateIfNecessary();
            };
        }
        protected function setSizeToFixMaxmimized():void{
            var _local1:IntRectangle = this.getMaximizedBounds();
            var _local2:IntRectangle = getComBounds();
            if ((this.state & MAXIMIZED_HORIZ) == MAXIMIZED_HORIZ){
                _local2.x = _local1.x;
                _local2.width = _local1.width;
            };
            if ((this.state & JFrame.MAXIMIZED_VERT) == JFrame.MAXIMIZED_VERT){
                _local2.y = _local1.y;
                _local2.height = _local1.height;
            };
            setBounds(_local2);
        }
        protected function precessIconified(_arg1:Boolean=true):void{
            this.doSubPopusVisible();
            dispatchEvent(new FrameEvent(FrameEvent.FRAME_ICONIFIED, _arg1));
        }
        protected function precessRestored(_arg1:Boolean=true):void{
            this.doSubPopusVisible();
            dispatchEvent(new FrameEvent(FrameEvent.FRAME_RESTORED, _arg1));
        }
        protected function precessMaximized(_arg1:Boolean=true):void{
            this.doSubPopusVisible();
            dispatchEvent(new FrameEvent(FrameEvent.FRAME_MAXIMIZED, _arg1));
        }
        private function doSubPopusVisible():void{
            var _local3:JPopup;
            var _local1:Array = getOwnedEquipedPopups();
            var _local2:int;
            while (_local2 < _local1.length) {
                _local3 = _local1[_local2];
                _local3.getGroundContainer().visible = _local3.shouldGroundVisible();
                _local2++;
            };
        }
        override function shouldOwnedPopupGroundVisible(_arg1:JPopup):Boolean{
            if (this.getState() == ICONIFIED){
                return (false);
            };
            return (super.shouldOwnedPopupGroundVisible(_arg1));
        }
        public function getState():int{
            return (this.state);
        }
        public function setResizer(_arg1:Resizer):void{
            if (_arg1 != this.resizer){
                this.resizer = _arg1;
                if (this.resizerController == null){
                    this.resizerController = ResizerController.create(this, _arg1);
                } else {
                    this.resizerController.setResizer(this.resizer);
                };
                this.resizerController.setResizable(this.isResizable());
            };
        }
        public function getResizer():Resizer{
            return (this.resizer);
        }
        public function setResizeDirectly(_arg1:Boolean):void{
            if (this.resizerController){
                this.resizerController.setResizeDirectly(_arg1);
            };
        }
        public function isResizeDirectly():Boolean{
            if (this.resizerController){
                return (this.resizer.isResizeDirectly());
            };
            return (false);
        }
        public function setDragDirectly(_arg1:Boolean):void{
            this.dragDirectly = _arg1;
            this.setDragDirectlySet(true);
        }
        public function isDragDirectly():Boolean{
            return (this.dragDirectly);
        }
        public function setDragDirectlySet(_arg1:Boolean):void{
            this.dragDirectlySet = _arg1;
        }
        public function isDragDirectlySet():Boolean{
            return (this.dragDirectlySet);
        }
        public function closeReleased():void{
            dispatchEvent(new FrameEvent(FrameEvent.FRAME_CLOSING, false));
            this.tryToClose();
        }
        public function tryToClose():void{
            if (this.defaultCloseOperation == HIDE_ON_CLOSE){
                hide();
            } else {
                if (this.defaultCloseOperation == DISPOSE_ON_CLOSE){
                    dispose();
                };
            };
        }
        protected function fireStateChanged(_arg1:Boolean=true):void{
            dispatchEvent(new InteractiveEvent(InteractiveEvent.STATE_CHANGED, _arg1));
        }
        override protected function initModalMC():void{
            super.initModalMC();
            getModalMC().addEventListener(MouseEvent.MOUSE_DOWN, this.__flashModelFrame);
        }
        private function __flashModelFrame(_arg1:MouseEvent):void{
            if (this.getFrameUI() != null){
                this.getFrameUI().flashModalFrame();
            };
        }

    }
}//package org.aswing 
